package com.swjd.bean;
import java.sql.*;
import java.util.*;
public class query {
	  private String trainid;//列车号
	  private String stationid;//始发站
	  private String destination;//终点站

                                                               
	  public String getStartplace() {
	    return stationid;
	  }
	  public void setStartplace(String st) {
	    this.stationid = st;
	  }
	  public String getDestination() {
	    return destination;
	  }
	  public void setDestination(String md) {
	    this.destination = md;
	  }
	 
	  public void setTrainid(String trainid) {
		    this.trainid =trainid;
		  }
	  public String getTrainid() {
		    return trainid;
		  }

	  
	  
	/*  public boolean hasLogin(String tid,String sp,String des){   //检查该车次是否存在 
	  	boolean f=true;
	   String sql="select train_id,startplace,destination " +
	   		"from ticket where train_id ='"+tid+"' and startplace='"+sp+"' and destination='"+des+"'";
	  	sqlBean db =new sqlBean();
	  	try{
	  	ResultSet rs=db.executeQuery(sql);
	  	if(rs.next()){ f=true;}
	  	else{ f=false;}
	  	}catch(Exception e){ e.getMessage();}
	  	return f;
	  	                       }*/
	  
	  //按车次查询该车次经过的所有站点
	  public ResultSet Trainquery(String trainid){
	    	String sql="select train_id,station_id,sequence,starttime from train_station " +
	                   " where train_id='"+trainid+"'order by sequence";
	                 sqlBean db= new sqlBean();
	                 ResultSet rs=db.executeQuery(sql);
	                 return rs;
	                 
	    	}	
      //查询经过两个站点的车次集合
	  public ResultSet Trainidquery(String start,String destination){
	    	String sql="select a.* from (select train_id,station_id,starttime " +
	    			" from train_station where station_id='"+start+"')as a" +
	    			" cross join (select train_id,station_id,starttime " +
	    			" from train_station where station_id='"+destination+"') as b" +
	    			" on a.train_id=b.train_id ";
	    			System.out.println(sql);
	                 sqlBean db= new sqlBean();
	                 ResultSet rs=db.executeQuery(sql);
	                 return rs;
	                 
	    	}
	  public ResultSet getMaxseat(String trainid){
	    	String sql="select max(seat) from ticket where train_id='"+trainid+"' ";
	                 sqlBean db= new sqlBean();
	                 ResultSet rs=db.executeQuery(sql);
	                 return rs;
	                 
	    	}
	  //按顺序查询经过两个站点之间的所有站点
		 public ResultSet Stationvarquery(String trainid,int seq1,int seq2){
			 String sql="select station_id from train_station " +
			 		"where train_id='"+trainid+"' and sequence between '"+seq1+"' and '"+seq2+"' order by sequence";
			 	sqlBean db= new sqlBean();
			 	ResultSet rs=db.executeQuery(sql);
			 	return rs;
		 }
	  //查询某个车次的某个站点的顺序号
		 public ResultSet Sequencequery(String trainid,String stationid){
			 String sql="select sequence from train_station where train_id='"+trainid+"' and station_id='"+stationid+"' ";//
			 	sqlBean db=new sqlBean();
			 	ResultSet rs=db.executeQuery(sql);
			 	return rs;
			 	
		 }
	  public ResultSet Stationquery(String station){
	    	String sql="select train_station.train_id,station_id,train_station.starttime,sequence,start_station,dest_station" +
	    			" from train_station,train where station_id='"+station+"' " +
	    			" and train_station.train_id=train.train_id";
	                 sqlBean db= new sqlBean();
	                 ResultSet rs=db.executeQuery(sql);
	                 return rs;	                 
	    	}
	  public ResultSet getStationdistance(String station1,String station2)
		 {
			String sql="select distance from station_station where station_id1='"+station1+"' " +
					" and station_id2='"+station2+"' ";
			sqlBean db=new sqlBean();
			ResultSet rs=db.executeQuery(sql);
			return rs;
		 }
		 
		 public ResultSet getUnitPrice()
		 {
			String sql="select unit_price from train";
			sqlBean db=new sqlBean();
			ResultSet rs=db.executeQuery(sql);
			return rs;
		 }
		 public ResultSet getTicketnum(String trainid)
		 {
			String sql="select ticket_num from train where train_id='"+trainid+"'";
			sqlBean db=new sqlBean();
			ResultSet rs=db.executeQuery(sql);
			return rs;
		 }
		 public ResultSet getCountnum(String userid,String start,String dest)
		 {
			String sql="select countnumber from book where user_id='"+userid+"' and" +
					" start_station='"+start+"' and dest_station='"+dest+"'";
			sqlBean db=new sqlBean();
			ResultSet rs=db.executeQuery(sql);
			return rs;
		 }
		
	  	                       
}
